<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>修改人员信息</title>
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}"/>
</head>
<body>
<input id="user_id" th:value="${user.id}" hidden="hidden"/>
<div id="view"></div>
</body>
<script th:src="@{/static/layui/layui.all.js}"></script>

<script id="user_view" type="text/html">
    <form class="layui-form" th:action="@{/user/update}" method="post" style="margin-top: 15px">
        <input name="id" value="{{d.id}}" hidden="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" name="userName" value="{{d.userName}}" required="required"  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input"/>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="sex" value="1" title="男" {{d.sex == 1 ? "checked":""}}/>
                <input type="radio" name="sex" value="0" title="女" {{d.sex == 0 ? "checked":""}}/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">年龄</label>
            <div class="layui-input-inline">
                <input type="text" name="age" value="{{d.age}}" lay-verify="required|number" placeholder="请输入年龄" autocomplete="off" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">Email</label>
            <div class="layui-input-inline">
                <input type="text" name="email" value="{{d.email}}"  lay-verify="required|email" placeholder="请输入email" autocomplete="off" class="layui-input"/>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-inline">
                <input type="text" name="phone" value="{{d.phone}}"  lay-verify="required|phone" placeholder="请输入电话号码" autocomplete="off" class="layui-input"/>
            </div>

        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">启用</label>
            <div class="layui-input-block">
                <input type="checkbox" name="enable" lay-skin="switch" {{d.enable ? "checked":""}} />
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="lay-submit" lay-filter="formUser">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

</script>
<script type="text/javascript" th:inline="javascript">

    var ctxPath = /*[[@{/}]]*/ '';
    layui.use(['laytpl','form','element'], function(){
        var laytpl = layui.laytpl;
        var form = layui.form;
        layui.$.ajax({
            type:"get",
            async:false,
            url: ctxPath + "/user/get/" + layui.$('#user_id').val(),
            success:function(data){
                if(data.status){
                    var data = data.data;
                    var getTpl = user_view.innerHTML
                        ,view = document.getElementById('view');

                    laytpl(getTpl).render(data, function(html) {
                        view.innerHTML = html;
                    });
                }
            }
        });
        form.render(); //更新全部
    });

</script>
</html>